// import count from '@feidao/web/atom/nodejs/db/count';
import query from '@dfeidao/atom-nodejs/db/query';
// import { IBaseTable } from '@feidao/web/atom/nodejs/db/interfaces';



interface Message {
	productid: string;
	client_type: string;
	menu_no: string;
}
interface Data {
	parent_no: string;
}

export default async function atom(msg: Message, action_id: string, session_id: string) {

	const systemid = '12';
	const { exec, prepare } = query(action_id, session_id, systemid);
	const productid = msg.productid;
	const client_type = msg.client_type;
	const menu_no = msg.menu_no;
	let no = 0;
	const asc = new Array();
	const desc = new Array();
	prepare('pub_menu', ['menu_no', 'menu_name', 'priority', 'systemid', 'parent_no', 'formid', 'client_type', 'description', 'priority', 'icon'], { productid, client_type, menu_no }, 200, 1, asc, desc);
	const [data] = await exec<Data>();
	if (data.length > 0) {
		const parent_no = data[0].parent_no;
		if (!parent_no) {
			no = 1;
			return no;
		} else {
			prepare('pub_menu', ['menu_no', 'menu_name', 'priority', 'systemid', 'parent_no', 'formid', 'client_type', 'description', 'priority', 'icon'], { productid, client_type, menu_no: parent_no }, 200, 1, asc, desc);
			const [data2] = await exec<Data>();
			if (data2.length > 0) {
				const parent_no1 = data2[0].parent_no;
				if (!parent_no1) {
					no = 2;
					return no;
				} else {
					no = 3;
					return no;
				}
			}
		}
	}
	return no;
}
